<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style>
            * {
                padding: 0;
                margin: 0;
            }
            .header {
                height: 60px;
                width: 100%;
                background-color: skyblue;
                position: fixed;
                top: -60px;
                font-size: 24px;
                color: white;
                text-align: center;
                line-height: 60px;
                transition: all 1s;
            }
            .goTop {
                width: 60px;
                height: 60px;
                display: none;
                position: fixed;
                bottom: 50px;
                right: 50px;
                background-color: pink;
                color: white;
                font-size: 24px;
                text-align: center;
            }
        </style>
    </head>
    <body>
        <div id="header" class="header">顶部通栏</div>
        <h1>1</h1>
        <h1>2</h1>
        <h1>3</h1>
        <h1>4</h1>
        <h1>5</h1>
        <h1>6</h1>
        <h1>7</h1>
        <h1>8</h1>
        <h1>9</h1>
        <h1>10</h1>
        <h1>11</h1>
        <h1>12</h1>
        <h1>13</h1>
        <h1>14</h1>
        <h1>15</h1>
        <h1>16</h1>
        <h1>17</h1>
        <h1>18</h1>
        <h1>19</h1>
        <h1>20</h1>
        <h1>21</h1>
        <h1>22</h1>
        <h1>23</h1>
        <h1>24</h1>
        <h1>25</h1>
        <h1>26</h1>
        <h1>27</h1>
        <h1>28</h1>
        <h1>29</h1>
        <h1>30</h1>
        <h1>31</h1>
        <h1>32</h1>
        <h1>33</h1>
        <h1>34</h1>
        <h1>35</h1>
        <h1>36</h1>
        <h1>37</h1>
        <h1>38</h1>
        <h1>39</h1>
        <h1>40</h1>
        <h1>41</h1>
        <h1>42</h1>
        <h1>43</h1>
        <h1>44</h1>
        <h1>45</h1>
        <h1>46</h1>
        <h1>47</h1>
        <h1>48</h1>
        <h1>49</h1>
        <h1>50</h1>
        <h1>51</h1>
        <h1>52</h1>
        <h1>53</h1>
        <h1>54</h1>
        <h1>55</h1>
        <h1>56</h1>
        <h1>57</h1>
        <h1>58</h1>
        <h1>59</h1>
        <h1>60</h1>
        <h1>61</h1>
        <h1>62</h1>
        <h1>63</h1>
        <h1>64</h1>
        <h1>65</h1>
        <h1>66</h1>
        <h1>67</h1>
        <h1>68</h1>
        <h1>69</h1>
        <h1>70</h1>
        <h1>71</h1>
        <h1>72</h1>
        <h1>73</h1>
        <h1>74</h1>
        <h1>75</h1>
        <h1>76</h1>
        <h1>77</h1>
        <h1>78</h1>
        <h1>79</h1>
        <h1>80</h1>
        <h1>81</h1>
        <h1>82</h1>
        <h1>83</h1>
        <h1>84</h1>
        <h1>85</h1>
        <h1>86</h1>
        <h1>87</h1>
        <h1>88</h1>
        <h1>89</h1>
        <h1>90</h1>
        <h1>91</h1>
        <h1>92</h1>
        <h1>93</h1>
        <h1>94</h1>
        <h1>95</h1>
        <h1>96</h1>
        <h1>97</h1>
        <h1>98</h1>
        <h1>99</h1>
        <h1>100</h1>
        <div id="go" class="goTop">回到顶部</div>
        <script>
            window.onscroll = function () {
                let scrollTop =
                    document.documentElement.scrollTop ||
                    document.body.scrollTop;
                if (scrollTop < 300) {
                    header.style.top = "-60px";
                    go.style.display = "none";
                } else if (scrollTop > 300) {
                    header.style.top = 0;
                    go.style.display = "block";
                }
            };
            go.onclick = function () {
                window.scrollTo({
                    top: 0,
                    behavior: "smooth",
                });
            };
        </script>
    </body>
</html>
